package stack.era.presentation.hud;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.GridLayout;

import javax.swing.BorderFactory;
import javax.swing.JLabel;
import javax.swing.JPanel;

import stack.era.constants.FrameAttributes.SideScreen;
import stack.era.constants.ImageAttributes.ImageCacheName;
import stack.era.presentation.images.ImageCache;
import stack.era.presentation.side_screen.SideScreenManager;

public class PlayerHUD extends JPanel {

	private static final long serialVersionUID = 8098414620898897946L;

	private HUDButton viewCharButton, viewJournalButton, viewInventoryButton,
			saveAndExitButton;

	private PlayerHealthBar healthBar;
	private PlayerFatigueBar fatigueBar;
	private PlayerExperienceBar xpBar;

	public PlayerHUD() {
		super();

		this.setBorder(BorderFactory.createLineBorder(Color.BLACK));

		this.setLayout(new GridLayout(4, 3));
		healthBar = new PlayerHealthBar();
		fatigueBar = new PlayerFatigueBar();
		xpBar = new PlayerExperienceBar();
		viewCharButton = new HUDButton("Your Character");
		viewCharButton.addActionListener(new ViewCharacterButtonControl());
		viewJournalButton = new HUDButton("Your Journal");
		viewInventoryButton = new HUDButton("Your Inventory");
		saveAndExitButton = new HUDButton("Save and Exit");
		this.add(healthBar);
		this.add(new JLabel());
		this.add(viewCharButton);
		this.add(fatigueBar);
		this.add(new JLabel());
		this.add(viewJournalButton);
		this.add(xpBar);
		this.add(new JLabel());
		this.add(viewInventoryButton);
		this.add(saveAndExitButton);
		this.add(new JLabel());
		this.add(new JLabel());
	}

	public void populate() {
		healthBar.populate();
		fatigueBar.populate();
		xpBar.populate();
		if (SideScreenManager.getInstance().isShown(SideScreen.CHARACTER)) {
			viewCharButton.setForeground(Color.WHITE);
		} else {
			viewCharButton.setForeground(Color.BLACK);
		}
	}

	@Override
	public void paintComponent(Graphics g) {
		super.paintComponent(g);
		g.drawImage(ImageCache.getInstance().getImage(
				ImageCacheName.DIRT_BACKGROUND), 0, 0, this.getWidth(), this
				.getHeight(), null, this);
	}

}
